package youcaihuaoa.weetop.com.ui.adapter

import android.graphics.Color
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.ColorUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.configs.PrefsManager
import com.robot.base.model.CustomListItemBean
import com.robot.base.model.ExamineBean
import com.robot.base.util.SpannableStringUtils
import com.robot.base.utils.pic.ImageLoaderUtils
import youcaihuaoa.weetop.com.R

class HomeItemAdapter(var type: Boolean = true) : BaseQuickAdapter<ExamineBean, BaseViewHolder>(
    R.layout.app_item_home
) {
    override fun convert(holder: BaseViewHolder, item: ExamineBean) {
        val pos = holder.adapterPosition
        holder.setVisible(R.id.v_line, pos != data.size - 1)
            .setText(
                R.id.tv_title,
                "${
                    if (item.public_user_id == PrefsManager.getUserInfo().id) {
                        "我"
                    } else {
                        item.user_name
                    }
                }发起的${item.public_title}"
            ).setGone(
                R.id.item_iv_state,
                if (type) {
                    item.public_status == "0"
                } else {
                    item.status == "0"
                }
            )
            .setGone(
                R.id.tv_reject_desc, if (type) {
                    item.public_status != "-1"
                } else {
                    item.status != "-1"
                }
            )
        if (type) {
            when (item.public_status) {
                "1" -> {
                    holder.setImageResource(R.id.item_iv_state, R.mipmap.app_ic_agree)
                }
                "-1" -> {
                    holder.setImageResource(R.id.item_iv_state, R.mipmap.app_ic_fail)
                }
            }
        } else {
            when (item.status) {
                "1" -> {
                    holder.setImageResource(R.id.item_iv_state, R.mipmap.app_ic_agree)
                }
                "-1" -> {
                    holder.setImageResource(R.id.item_iv_state, R.mipmap.app_ic_fail)
                }
            }
        }
        val sp = SpannableStringUtils.getBuilder("申请时间：")
            .append(item.public_create_time ?: "")
            .setForegroundColor(Color.parseColor("#999999"))
            .create()
        holder.setText(R.id.tv_apply_time, sp)
        val sp1 = SpannableStringUtils.getBuilder("审批时间：")
            .append(
                if (type) {
                    item.public_update_time ?: ""
                } else {
                    item.examine_time ?: ""
                }
            )
            .setForegroundColor(Color.parseColor("#999999"))
            .create()
        holder.setText(R.id.tv_approve_time, sp1)


    }
}